# -*- coding:utf-8 -*-
'''
@author: xiaoming
@contact: lishihui0129@163.com
@time: 2017/6/29 16:02
@desc:
'''
import re
import os
from myUtil import weichatPattern,flagSplitPattern
from mysqlHelper import close,connectDB,insertSql


def weichatExtract(string):
    '''
    :param string: 待提取对象
    :return:提取结果
    '''
    weizhi=string.find(u'微信')
    if weizhi==-1:
        weizhi=0

    string1=(string[weizhi:]).replace(u'微信',u'')
    temp=[]
    res=string1.strip()
    if len(res)>3:
        temp.append(res)
    return temp


# def prefixFlag(string):
#     '''
#     :param string: 待提取对象
#     :return:前缀信息
#     '''
#     if '微信' in string:
#         ind=string.index('微信')
#     elif '公众号' in string:
#         ind=string.index('公众号')
#     elif 'v' in string:
#         ind=string.index('V')
#     else:
#         ind=0
#     temp=string[:ind]
#     # res=re.split(r'，|:|!|,|;| |（|\(|\[|【',temp)
#     res=re.split(flagSplitPattern,temp)
#     return res[-1].strip()

# def insertWeichatTable(string):
#     res=re.findall(weichatPattern,string)
#     res=list(set(res))
#     flag=prefixFlag(string)
#     connectDB()
#     sql="insert into weichat(weichat_value,prefix) values(%s,%s)"
#
#     for each in res:
#         param=(each,flag)
#         insertSql(sql,param)
#     close()